package com.zbkj.admin.controller.brand;

import com.zbkj.common.page.CommonPage;
import com.zbkj.common.result.CommonResult;
import com.zbkj.common.request.PageParamRequest;
import jdk.nashorn.internal.ir.annotations.Ignore;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;
import com.zbkj.common.request.CommonBatchRequest;
import com.zbkj.common.annotation.LogControllerAnnotation;
import com.zbkj.common.enums.MethodType;

import com.zbkj.service.service.AttractActivityService;
import com.zbkj.common.model.agent.AttractActivity;
import com.zbkj.common.response.AttractActivityDetailResponse;

import com.zbkj.common.request.AttractActivitySaveRequest;
import com.zbkj.common.request.AttractActivitySearchRequest;
import com.zbkj.common.response.AttractActivityPageDataResponse;

import javax.validation.Valid;

/**
 * 邀约活动管理 前端控制器
 */
@Slf4j
@RestController
@RequestMapping("api/admin/brand/attract/activity")
@Api(tags = "邀约活动管理") //配合swagger使用

public class BrandAttractActivityController {

    @Autowired
    private AttractActivityService attractActivityService;

    /**
     * 分页显示邀约活动表
     *
     * @param request          搜索条件
     * @param pageParamRequest 分页参数
     * @author Caiyc
     * @since 2025-08-07
     */
    @ApiOperation(value = "分页列表") //配合swagger使用
    @RequestMapping(value = "/page/list", method = RequestMethod.GET)
    public CommonResult<CommonPage<AttractActivityPageDataResponse>> getList(@Validated AttractActivitySearchRequest request,
                                                                   @ModelAttribute PageParamRequest pageParamRequest) {
        CommonPage<AttractActivityPageDataResponse> attractActivityCommonPage = CommonPage.restPage(attractActivityService.getList(request, pageParamRequest));
        return CommonResult.success(attractActivityCommonPage);
    }

    /**
     * 新增邀约活动表
     * @param attractActivitySaveRequest 新增参数
     * @author Caiyc
     * @since 2025-08-07
     */
    @ApiOperation(value = "新增")
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public CommonResult<String> save(@RequestBody @Validated AttractActivitySaveRequest attractActivitySaveRequest) {
        if(attractActivityService.create(attractActivitySaveRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 删除邀约活动表
     * @param id Integer
     * @author Caiyc
     * @since 2025-08-07
     */
    @Ignore
    @ApiOperation(value = "删除")
    @RequestMapping(value = "/delete", method = RequestMethod.GET)
    public CommonResult<String> delete(@RequestParam(value = "id") Integer id) {
        if(attractActivityService.removeById(id)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 批量删除
     * @param request
     * @return
     * @author Caiyc
     * @since 2025-08-07
     */
    @LogControllerAnnotation(intoDB = true, methodType = MethodType.DELETE, description = "批量删除溯源套餐")
    @ApiOperation(value = "批量删除")
    @RequestMapping(value = "/batch/delete", method = RequestMethod.POST)
    public CommonResult<String> batchDelete(@RequestBody @Validated CommonBatchRequest request) {
        if (attractActivityService.batchDelete(request.getIdList())) {
            return CommonResult.success();
        }
        return CommonResult.failed();
    }

    /**
     * 修改邀约活动表
     * @param attractActivityRequest 修改参数
     * @author Caiyc
     * @author Caiyc
     * @since 2025-08-07
     */
    @ApiOperation(value = "修改")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public CommonResult<String> update(@RequestBody @Validated AttractActivitySaveRequest attractActivityRequest) {
        if (attractActivityService.update(attractActivityRequest)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

    /**
     * 查询邀约活动表详情
     * @param id Integer
     * @author Caiyc
     * @since 2025-08-07
     */
    @ApiOperation(value = "详情")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public CommonResult<AttractActivityDetailResponse> getDetails(@PathVariable("id") Integer id) {
        return CommonResult.success(attractActivityService.getDetails(id));
    }

    @LogControllerAnnotation(intoDB = true, methodType = MethodType.UPDATE, description = "修改后台管理员状态")
    @ApiOperation(value = "修改后台管理员状态")
    @RequestMapping(value = "/updateStatus", method = RequestMethod.GET)
    public CommonResult<String> updateStatus(@RequestParam(value = "id") @Valid Integer id, @RequestParam(value = "status") @Valid Integer status) {
        if (attractActivityService.updateStatus(id, status)) {
            return CommonResult.success("修改成功");
        }
        return CommonResult.failed("修改失败");
    }

    @ApiOperation(value = "复制活动")
    @RequestMapping(value = "/copy/{id}", method = RequestMethod.POST)
    public CommonResult<String> copy(@PathVariable("id") Integer id) {
        if(attractActivityService.copy(id)) {
            return CommonResult.success();
        } else {
            return CommonResult.failed();
        }
    }

}



